const classRegex = /^([a-z]+(-[a-z0-9]+)*)$/;

const customCssClassNameRule = {
  create: function(context) {
    return {
      JSXOpeningElement(node) {
        node.attributes.forEach(attr => {
          if (attr.type === 'JSXAttribute' && attr.name.name === 'className') {
            if (attr.value.type === 'Literal') {
              const classNames = attr.value.value.split(/\s+/);
              classNames.forEach(className => {
                if (!classRegex.test(className)) {
                  context.report({
                    node,
                    message: `CSS class name '${className}' must be in kebab-case.`,
                  });
                }
              });
            }
          }
        });
      },
    };
  },
};


export default {
  'custom-css-class-name': customCssClassNameRule,
};